package com.example.commom.model;

import com.example.commom.exception.ErrorCode;
import lombok.Data;

/**
 * @author: bebm
 * @date: 2022/3/30 19:56
 * @description:
 */
@Data
public class ApiResult<T> {

    public static final ApiResult OK_EMPTY = ok((Object) null);

    private String errorMsg;

    private String errorCode;

    private T data;

    private String dataDt;

    protected ApiResult() {

    }

    public static <T> ApiResult<T> ok(T data) {
        ApiResult<T> ok = new ApiResult<>();
        ok.setErrorCode(ErrorCode.OK.getCode());
        ok.setData(data);
        return ok;
    }

    public static <T> ApiResult<T> error(String errorCode,String errorMsg) {
        ApiResult<T> error = new ApiResult<>();
        error.setErrorCode(errorCode);
        error.setErrorMsg(errorMsg);
        return error;
    }

}
